<?php

include_once($_SERVER['DOCUMENT_ROOT'] ."/include/user/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/tucao/inc.php");

include_once($_SERVER['DOCUMENT_ROOT'] ."/include/mblog/inc.php");
error_reporting(E_ERROR | E_PARSE);
if(! security_check::check_refer())
{
	throw new Exception("来路不明");
}

//error_reporting(E_ALL);
//所有的参数
$g_cgival 	= array();
//存储中间数据 非输出数据 可以不用
$g_pro	 	= array();
//要显示的数据 输出数据
$g_show 	= array();

function check_cgi_pro()
{		
	global $g_cgival, $g_pro, $g_show, $config;
	
	cgi::both($g_cgival['t'], "t", "json");
		
	cgi::both($g_cgival['callback'], "callback", "");
	$g_cgival['callback'] = string::un_html(string::un_script_code($g_cgival['callback']));
	
	cgi::both($g_cgival['id'], "id", 0);
	

	
}


function get_data()
{
	global $g_cgival, $g_pro, $g_show, $config;
	
	$id = $g_cgival['id'];
	if(!$id)
	{
		
		throw new Exception("id不能为空!");
	}
	
	$db_mblog_pic_content = new db_mblog_pic_content();
	$item = $db_mblog_pic_content->get_mblog_pic_content_item($id);
	
	$item["create_time"] = substr($item["create_time"],5,11);
	$item["source"] = preg_replace("/<.*?>/","",$item["source"]);
	
	$item["small_pic"] = str_replace("/bmiddle/","/thumbnail/",$item["pic"]);
	$item["big_pic"] = str_replace("/bmiddle/","/large/",$item["pic"]);
	$item["mw_pic"] = str_replace("/bmiddle/","/mw690/",$item["pic"]);
		
		
	$g_show["data"] = $item;
	
	$user_info = new user_info();
	$is_login = $user_info->is_logined();
	if($is_login)
	{
		$user_detail_info = $user_info->get_cur_user_info();
		$uid = $user_detail_info["uid"];
		
	}
	
	
	$db_mblog_reply = new db_mblog_reply();
	$list = $db_mblog_reply->get_list_by_mid($id,1,3);
	
	$admin_uid = user_info::check_super_admin();
	
	
	foreach($list as $key => $value)
	{
		if($admin_uid || $uid ==$value["create_uid"])
		{
			$list[$key]["show_del"] = 1;
		}
		else
		{
			$list[$key]["show_del"] = 0;
		}
		$list[$key]["user_info"] = $user_info->get_user_info_by_uid($value["create_uid"]);
	}
	
	$g_show["data"]["list"] = $list;
	
}
try {
	
	check_cgi_pro();
	get_data();
	$g_show["error"] = 0;
	$g_show["errmsg"] = "";
	
	
} 
catch (Exception $e) 
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
	
}
show_pro();

exit;

function show_pro()
{
	global $g_cgival, $g_pro, $g_show, $config;
	
	if ($g_cgival['t'] == "serialize")
	{
		echo serialize($g_show);
	}
	elseif ($g_cgival['t'] == "json")
	{
		echo output::json("json", $g_show, $g_cgival['callback']);
	}
	elseif($g_cgival['t'] == "jsonp")
	{
		echo output::json("jsonp", $g_show, $g_cgival['callback']);
	}
	elseif($g_cgival['t'] == "perl")
	{
		$string = php_to_perl::php_array_to_perl_hash($g_show);
		$string = mb_convert_encoding($string, "GBK", "UTF-8");
		echo $string;
	}
	elseif($g_cgival['t'] == "iframe")
	{
		header("location:{$g_cgival['link']}");
	}
	else
	{
		echo output::json("jsonp", $g_show, $g_cgival['callback']);
	}
}

